<template>
  <div class="list-page">
    <div class="list-page-search" v-if="tableInfo.showSearch">
      <NForm inline :model="tableInfo.queryForm" label-placement="left">
        <NFormItem label="作品">
          <y-resource
            v-model="tableInfo.queryForm.photo_id"
            @change="queryData"
          />
        </NFormItem>
        <NFormItem label="人员">
          <y-select-usr
            v-model="tableInfo.queryForm.user_id"
            @change="queryData"
          />
        </NFormItem>
        <NFormItem>
          <NButton type="primary" @click="queryData">
            <template #icon>
              <n-icon>
                <i class="esayIcon esayIcon-sousuo"></i>
              </n-icon>
            </template>
            <span>搜索</span>
          </NButton>
        </NFormItem>
      </NForm>
    </div>
    <div class="list-page-main">
      <div class="pb20 flex flex-between">
        <div></div>
        <div>
          <n-button
            tertiary
            circle
            @click="tableInfo.showSearch = !tableInfo.showSearch"
          >
            <template #icon>
              <i class="esayIcon esayIcon-sousuo"></i>
            </template>
          </n-button>
          <n-button class="ml15" tertiary circle @click="handToast">
            <template #icon>
              <i class="esayIcon esayIcon-daochu"></i>
            </template>
          </n-button>
          <n-button class="ml15" tertiary circle @click="handToast">
            <template #icon>
              <i class="esayIcon esayIcon-daoru"></i>
            </template>
          </n-button>
        </div>
      </div>
      <NDataTable
        style="flex: 1"
        flex-height
        :scroll-x="1000"
        :columns="columns"
        :row-key="rowKey"
        :loading="tableInfo.listLoading"
        :data="tableInfo.tableData"
      />
      <div class="pagination mt20">
        <NPagination
          v-model:page="tableInfo.queryForm.pageNo"
          :page-count="tableInfo.total"
          :page-sizes="tableInfo.pageSizes"
          show-quick-jumper
          show-size-picker
          @updatePage="pageChange"
          @updatePageSize="sizeChange"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { h } from 'vue'
import {
  NButton,
  NDataTable,
  NForm,
  NFormItem,
  NIcon,
  useMessage,
  NPagination
} from 'naive-ui'
import type { DataTableColumns } from 'naive-ui'
import { useApi } from '@/hooks/useApi'
import YSelectUsr from '@/components/yang/yselectpcuser/index.vue'
import YResource from '@/components/yang/yresource/index.vue'
import tagApi from '@/service/api/photo/tag'
/**
 * 抓包
 */
const { tableInfo, pageChange, sizeChange, queryData } = useApi({
  getData: tagApi.changeList,
  initForm: {
    photo_id: null,
    user_id: null
  }
})
/**
 *  获取列表
 * */
const rowKey = (row: any) => row.id
const columns: DataTableColumns<any> = [
  {
    title: '标题',
    width: '200px',
    key: 'photo_name',
    ellipsis: {
      tooltip: true
    }
  },
  {
    title: '用户昵称',
    key: 'nickname',
    width: '200px',
    ellipsis: {
      tooltip: true
    }
  },
  {
    title: '新增标签',
    key: 'addTag',
    align: 'center',
    ellipsis: {
      tooltip: true
    },
    render(row: any) {
      return h('div', {}, { default: () => row.addTag.toString() })
    }
  },
  {
    title: '删除标签',
    key: 'addTag',
    align: 'center',
    ellipsis: {
      tooltip: true
    },
    render(row: any) {
      return h('div', {}, { default: () => row.delTag.toString() })
    }
  },
  {
    title: '现标签',
    key: 'addTag',
    align: 'center',
    ellipsis: {
      tooltip: true
    },
    render(row: any) {
      return h('div', {}, { default: () => row.photo_tags.toString() })
    }
  }
]
const toast = useMessage()
const handToast = () => {
  toast.warning('开发中')
}
</script>

<style lang="scss" scoped></style>
